package com.jdrx.sw.sewage.common.filter;

import com.jdrx.sw.sewage.common.wrapper.HeaderMapRequestWrapper;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Component
public class HttpServletRequestFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HeaderMapRequestWrapper requestWrapper = null;
        if (request instanceof HttpServletRequest)
            requestWrapper = new HeaderMapRequestWrapper((HttpServletRequest) request);

        if (null == requestWrapper) chain.doFilter(request, response);
        else chain.doFilter(requestWrapper, response);
    }

    @Override
    public void destroy() {

    }
}